﻿/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
**   * Redistributions of source code must retain the above copyright
**     notice, this list of conditions and the following disclaimer.
**   * Redistributions in binary form must reproduce the above copyright
**     notice, this list of conditions and the following disclaimer in
**     the documentation and/or other materials provided with the
**     distribution.
**   * Neither the name of The Qt Company Ltd nor the names of its
**     contributors may be used to endorse or promote products derived
**     from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Controls.Material 2.0
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.12
import QtGraphicalEffects 1.0
import QtQuick.Window 2.2

Item {
    property bool isLogining: false

    property string myMail
    property string myPwd
    Component.onCompleted: {
        //kong_w@foxmail.com
        //852266938@qq.com

        //                ChatManage.sendRegiste("kong_w@foxmail.com","123")
        //        delegateLoader.source="Root.qml"
    }

    Connections{
        target: ChatManage
        function onLoginAnswer(value,errMsg){
            materialUI.hideLoading();
            if(value){
                console.log("登录成功")
                ChatManage.writeConfigValue("UserInfo/Mail",myMail)
                ChatManage.writeConfigValue("UserInfo/Pwd",myPwd)
                isLogining = true
                delegateLoader.source="Root.qml"
            }
            else{
                console.log("登录失败")
                isLogining = false
                materialUI.showSnackbarMessage(errMsg)
            }
        }
    }

    Rectangle{
        anchors{
            left: parent.left
            right: parent.right
            top: parent.top
        }
        height: parent.height/4
        color: "#00000000"
        Label{
            id:title
            anchors.fill: parent
            text: "内部交流传输工具"
            font.pixelSize: 38
            anchors.centerIn: parent
            horizontalAlignment: Label.AlignHCenter
            verticalAlignment: Label.AlignVCenter
            layer.enabled: true
            layer.effect: DropShadow {
                horizontalOffset: 0
                verticalOffset: 0
                radius: 4
                samples: 9
                color: "#000000"
                spread: 0
            }
        }
    }


    RectangularGlow {
        z: -1
        anchors.fill: first
        glowRadius: 6
        spread: 0.22
        color: "#20000000"
    }

    Rectangle{
        id:first
        Layout.fillWidth: true
        Layout.minimumWidth: 300
        Layout.minimumHeight: 280
        anchors{
            left:parent.left
            leftMargin: 100
            right: parent.right
            rightMargin: 100
            top: parent.top
            topMargin: (parent.height-height)/2
        }
        height: 300
        z:2
        UserInfo{
            anchors.fill: parent

            onButtonClicked: {
                //                console.log(email,pwd)
                myMail = email
                myPwd = pwd
                if(!email){
                    materialUI.showSnackbarMessage("请输入邮箱")
                    isLogining = false
                    return
                }
                if(!pwd){
                    materialUI.showSnackbarMessage("请输入密码")
                    isLogining = false
                    return
                }

                materialUI.showLoading( "" );
                ChatManage.sendRegiste(email,pwd)
            }
        }
    }
    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.LeftButton
        z:1
        property point clickPos: "0,0"

        onPressed: {
            clickPos  = Qt.point(mouse.x,mouse.y)
            //console.log("mouse Pressed")
        }
        onPositionChanged: {
            var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
            window.setX(window.x+delta.x)
            window.setY(window.y+delta.y)
        }
        onReleased: {
            var delta = Qt.point(mouse.x-clickPos.x, mouse.y-clickPos.y)
            window.setX(window.x+delta.x)
            window.setY(window.y+delta.y)
        }
    }

    Image {
        id: close
        z:2
        anchors{
            right: parent.right
            rightMargin: 5
            top: parent.top
            topMargin: 5
        }
        width: 20
        height: width
        fillMode:Image.PreserveAspectFit
        source: "qrc:/close.png"
        scale:0.8
        layer.enabled: true
        layer.effect:DropShadow {
            horizontalOffset: 0
            verticalOffset: 0
            radius: 4
            samples: 9
            color: "#000000"
            spread:0
        }
        MouseArea{
            anchors.fill: parent
            hoverEnabled: true
            ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
            ToolTip.text: qsTr("Close")
            onEntered: {
                close.scale = 1
                ToolTip.visible = true
            }
            onExited: {
                close.scale = 0.8
                ToolTip.visible = false
            }
            onClicked: {
                window.close()
            }
        }
    }
    Rectangle{
        id:min
        z:2
        anchors{
            right: close.left
            rightMargin: 12
            top: close.top
        }
        width: close.width
        height: width
        color: "#00000000"

        Image {
            id:minImag
            scale: 0.8
            anchors.centerIn: parent
            anchors.fill: parent
            anchors.topMargin: 5
            anchors.bottomMargin: 5
            anchors.leftMargin: 2
            anchors.rightMargin: 2
//                fillMode:Image.PreserveAspectFit
            source: "qrc:/min.png"
            layer.enabled: true
            layer.effect:DropShadow {
                horizontalOffset: 0
                verticalOffset: 0
                radius: 4
                samples: 9
                color: "#000000"
                spread:0
            }
        }
        MouseArea{
            anchors.fill: parent
            hoverEnabled: true
            ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval
            ToolTip.text: qsTr("Minimize")
            onEntered: {
                minImag.scale = 1
                ToolTip.visible = true
            }
            onExited: {
                minImag.scale = 0.8
                ToolTip.visible = false
            }
            onClicked: {
                window.visibility = Window.Minimized
            }
        }
    }


}


/*##^##
Designer {
    D{i:0;formeditorZoom:0.9}
}
##^##*/
